package com.lc.cehui.ui.activity.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.cehui.R;
import com.lc.cehui.app.AppActivity;
import com.lc.cehui.http.response.SuggestTypeBean;
import com.lc.cehui.util.SettingBar;

import org.jetbrains.annotations.NotNull;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 举报列表
 */
public class ComplaintActivity extends AppActivity {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private BaseQuickAdapter<SuggestTypeBean.DataBean, BaseViewHolder> reportadapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_complaint;
    }

    @Override
    protected void initView() {
        reportadapter=new BaseQuickAdapter<SuggestTypeBean.DataBean, BaseViewHolder>(R.layout.item_complaint) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, SuggestTypeBean.DataBean datebean) {
                SettingBar sb_name=holder.getView(R.id.sb_name);
                sb_name.setLeftText(datebean.getTitle());
            }
        };
        recyclerView.setAdapter(reportadapter);
        reportadapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {
                    startActivity(new Intent(ComplaintActivity.this,ComplaintDetailsActivity.class).putExtra("title",reportadapter.getData().get(position).getTitle()).putExtra("msgId",reportadapter.getData().get(position).getMsg_id()+""));
            }
        });
    }

    @Override
    protected void initData() {
        report_type();
    }

    private void report_type() {
        EasyHttp.post(this)
                .api("api/report_type")
                .request(new HttpCallback<SuggestTypeBean>(this) {

                    @Override
                    public void onSucceed(SuggestTypeBean data) {

                        if (data.getCode().equals("200")) {
                            reportadapter.setNewData(data.getData());

                        }

                    }
                });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
